<template>
  <div class="table-page-search-wrapper">
    <a-card>
      <a-form layout="vertical">
        <a-row :gutter="48">
          <a-col :md="6" :sm="12">
            <a-form-item
                label="学号"

            >
              <a-input v-model="queryParam.xh"/>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="12">
            <a-form-item
              label="姓名"

            >
              <a-input v-model="queryParam.xm"/>
            </a-form-item>
          </a-col>
          <template v-if="advanced">
            <a-col :md="6" :sm="12">
              <a-form-item
                label="学生来源"
              >
                <a-select :allowClear="true" v-model="queryParam.xslxm">
                  <a-select-option v-for="i in TYPE0503" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="12">
              <a-form-item
                label="学生类别"

              >
                <a-select v-model="queryParam.xslbm">
                  <a-select-option v-for="i in TYPE0075" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="12">
              <a-form-item label="院系">
                <a-select :disabled="selectMenu.yxList.length === 1" allowClear v-model="queryParam.ssyxm" @change="yxChange" showSearch :filterOption="filterOption">
                  <a-select-option v-for="i in selectMenu.yxList" :key="i.id" :value="i.dwh">{{ i.dwh }} {{ i.dwmc }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="12">
              <a-form-item label="专业">
                <a-select allowClear v-model="queryParam.sszym" showSearch :filterOption="filterOption">
                  <a-select-option v-for="i in selectMenu.zyList" :key="i.id" :value="i.zyh">{{ i.zyh}} {{ i.zymc }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="12">
              <a-form-item label="年级">
                <a-select allowClear v-model="queryParam.sznj">
                  <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="12">
              <a-form-item label="学籍状态">
                <a-select allowClear v-model="queryParam.xjztm" placeholder="请选择">
                  <a-select-option value="1">在读</a-select-option>
                  <a-select-option value="7">毕业</a-select-option>
                  <a-select-option value="8">结业</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="12">
              <a-form-item label="修课状态">
                <a-select allowClear v-model="queryParam.xkzt" placeholder="请选择">
                  <a-select-option value="1">修满</a-select-option>
                  <a-select-option value="0">未修满</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="12">
              <a-form-item label="答辩验证">
                <a-select allowClear v-model="queryParam.dbyz">
                  <!-- <a-select-option value="01">不通过</a-select-option>
                  <a-select-option value="02">通过</a-select-option> -->
                  <a-select-option v-for="i in TYPE0505" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </template>
          <a-col :md="6" :sm="12">
              <a-form-item label="照片验证">
                <a-select allowClear v-model="queryParam.zpyz" placeholder="请选择">
                  <a-select-option value="01">已验证</a-select-option>
                  <a-select-option value="02">未验证</a-select-option>
                </a-select>
              </a-form-item>
          </a-col>
          <a-col :md="6" :sm="12">
              <a-form-item label="有无照片">
                <a-select allowClear v-model="queryParam.ywzp" placeholder="请选择">
                  <a-select-option value="01">有</a-select-option>
                  <a-select-option value="02">无</a-select-option>
                </a-select>
              </a-form-item>
          </a-col>
          <!-- <a-col :md="12" :sm="12">
            <span class="table-page-search-submitButtons" >
              <a-button type="primary" @click="$refs.table.refresh(true)" style="margin:0 10px">查询</a-button>
              <a-button type="primary" @click="$refs.table.refresh(true)" style="margin:0 10px">导出</a-button>
              <a-button type="primary" @click="$refs.table.refresh(true)" style="margin:0 10px">设置毕业学籍状态</a-button>
              <a-button type="primary" @click="$refs.table.refresh(true)" style="margin:0 10px">设置结业学籍状态</a-button>
              <a @click="advanced = !advanced" style="margin-left: 8px">
                {{ advanced ? '收起' : '展开' }}
                <a-icon :type="advanced ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col> -->
        </a-row>
        <a-row :md="24" :sm="24">
          <span class="table-page-search-submitButtons" :style="{ overflow: 'hidden' }">
            <a-button type="primary" @click="$refs.table.refresh(true)" style="margin:0 10px">查询</a-button>
            <!-- <a-button type="primary" style="margin:0 10px" @click="handleExport">导出</a-button> -->
            <a-button type="primary" @click="changeStatus(7)" >设置毕业学籍状态</a-button>
            <a-button type="primary" @click="changeStatus(8)" style="margin:0 10px">设置结业学籍状态</a-button>
          <a-button @click="queryParam = {};$refs.table.refresh()" style="margin-left: 8px;">重置</a-button>

            <a @click="advanced = !advanced" style="margin-left: 8px">
              {{ advanced ? '收起' : '展开' }}
              <a-icon :type="advanced ? 'up' : 'down'"/>
            </a>
          </span>
        </a-row>
      </a-form>
    </a-card>

    <a-card :bordered="false" style="margin-top: 10px">
      <s-table
        v-if="init"
        ref="table"
        size="default"
        rowKey="id"
        :columns="columns"
        :data="loadData"
        :alert="{show: true}"
        :scroll="{ x: 1800 }"
        :pageSize="parameter.pageSize"
      >
        <span slot="serial" slot-scope="text, record, index">
          {{ index + 1 + (parameter.pageNo - 1) * parameter.pageSize }}
        </span>
        <span slot="xkztmc" slot-scope="text, record">
          <template v-if="text === '未修满'">
            <a @click="showKcList(record.xh)">{{ text }}</a>
          </template>
          <template v-else>
            {{ text }}
          </template>
          <!-- {{ index + 1 + (parameter.pageNo - 1) * parameter.pageSize }} -->
        </span>
        <template slot="action" slot-scope="text,record">
          <a @click="showScore(record.xh)">成绩</a>
          <a v-if="record.zpshzt" @click="check(record,'see')">查看</a>
          <a v-else @click="check(record,'check')">审核</a>

        </template>
      </s-table>
    </a-card>
    <creditModal
      ref="check"
      :visible="creditVisible"
      :isCredit="isCredit"
      @cancel="creditVisible = false"
    />
    <!-- 审核 -->
    <checkPic 
      ref="checkPic"
      :visible="checkVisible"
      :infoList="infoList"
      :type="type"
      @save="checkInfo"
      @cancel="checkVisible = false"/>
    <!-- 成绩 -->
    <kc-list ref="kc" :visible="kcVisible" :list="wxKcList" @cancel="kcVisible = false"/>
  </div>
</template>

<script>
import { STable } from '~'
import { mapState } from 'vuex'
import kcList from './kcList'
import creditModal from './creditModal'
import checkPic from './checkPic'

export default {
  data () {
    return {
      type: '',
      infoList: '',
      checkVisible: false,
      creditVisible: false,
      isCredit: false,
      advanced: true,
      queryParam: {
        xjztm: ''
      },
      columns: [
        {
          title: '序号',
          scopedSlots: { customRender: 'serial' }
        },
        {
          title: '学号',
          dataIndex: 'xh'
        },
        {
          title: '学籍状态',
          dataIndex: 'xjztmc'
        },
        {
          title: '姓名',
          dataIndex: 'xm'
        },
        {
          title: '培养单位',
          dataIndex: 'ssyxmc'
        },
        {
          title: '所属专业',
          dataIndex: 'sszymc'
        },
        {
          title: '学生类别',
          dataIndex: 'xslbmc'
        },
        {
          title: '课程学分',
          dataIndex: 'kcxf'
        },
        {
          title: '课程学分审核',
          dataIndex: 'xfsh'
        },
        {
          title: '预答辩审核',
          dataIndex: 'ydbsh'
        },
        {
          title: '答辩审核',
          dataIndex: 'dbsh'
        },
        {
          title: '修课状态',
          dataIndex: 'xkztmc',
          scopedSlots: { customRender: 'xkztmc' }
        },
        {
          title: '毕结业结论',
          dataIndex: 'bjyjl'
        },
        {
          title: '操作',
          dataIndex: 'cz',
          fixed: 'right',
          width: 120,
          scopedSlots: { customRender: 'action' }
        }
      ],
      parameter: {
        pageNo: 1,
        pageSize: 10
      },
      loadData: parameter => {
        this.parameter = parameter
        parameter.pageNum = parameter.pageNo
        let params = Object.assign(this.queryParam, parameter)
        return this.$api.cultivate.graduateList(params).then(res => {
          return {
            data: res.data.rows,
            pageNo: parameter.pageNo,
            pageSize: parameter.pageSize,
            totalPage: Math.ceil(res.data.total / parameter.pageSize),
            totalCount: res.data.total
          }
        })
      },
      selectMenu: {
        yxList:[]
      },
      visible: false,
      init: false,
      kcVisible: false,
      wxKcList: []
    }
  },
  components: {STable, kcList, creditModal,checkPic},
  computed: {
    ...mapState({
      TYPE0075: state => state.app['TYPE0075'],
      TYPE0073: state => state.app['TYPE0073'],
      TYPE0503: state => state.app['TYPE0503'],
      TYPE0505: state => state.app['TYPE0505'],
      TYPE0126: state => state.app['TYPE0126']
    })
  },
  created () {
    this.$store.dispatch('app/setDictionary', 'TYPE0075')
    this.$store.dispatch('app/setDictionary', 'TYPE0073')
    this.$store.dispatch('app/setDictionary', 'TYPE0505')
    this.$store.dispatch('app/setDictionary', 'TYPE0126')
    this.$store.dispatch('app/setDictionary', 'TYPE0503')
    this.initSelectMenu()
  },
  methods: {
    initSelectMenu () {
      let allRequest = [
        this.$api.base.collegeAll(),
        this.$store.dispatch('app/sysInfo')
      ]
      Promise.all(allRequest).then(res => {
        this.selectMenu = {
          yxList: res[0].data
        }
        if(this.selectMenu.yxList && this.selectMenu.yxList.length == 1){
          this.$set(this.queryParam, 'ssyxm', this.selectMenu.yxList[0].dwh)
          this.yxChange(this.queryParam.ssyxm)
        }
        this.$set(this.queryParam, 'sznj', res[1].currentGrade)
        this.init = true
      })
    },
    filterOption (value, op) {
      return op.componentOptions.children[0].text.indexOf(value) !== -1
    },
    yxChange (code) {
      this.$set(this.queryParam, 'zyh', '')
      if (code) {
        this.$api.base.majorAll({lsdwh: code}).then(res => {
          this.$set(this.selectMenu, 'zyList', res.data)
        })
      } else {
        this.$set(this.selectMenu, 'zyList', [])
      }
    },
    handleExport(){
      this.$export('foster/bygl/exportByzgsh',this.queryParam)
    },
    showKcList (xh) {
      this.kcVisible = true
      this.$refs.kc.loading = true
      this.$api.cultivate.graduateKcList({xh,xkzt: 0}).then(res => {
        this.wxKcList = res.data
      }).finally(() => {
        this.$refs.kc.loading = false
      })
    },
    changeStatus (code) {
      this.$confirm({
        title: `确定要将 "所选条件下" 所有验证${code === 7 ? '' : '不'}通过的学生设置为${code === 7 ? '毕业' : '结业'}吗？?`,
        content: '当您点击确定按钮后，这些学生毕业状态将会被修改',
        centered: true,
        onOk: () => {
          this.$api.cultivate.graduateChangeStatus({...this.queryParam, bylx: code}).then(res => {
            this.$message.success(res.msg)
            this.$refs.table.refresh(false)
            this.$refs.table.clearSelected()
          })
        },
        onCancel: () => {
        }
      })
    },
    showScore (xh) {
      this.creditVisible = true
      this.isCredit = false
      this.$api.cultivate.scoreStuInfo(xh).then(res => {
        this.$refs.check.detail = res.data
      })
    },
    check(infoList,type){
      this.infoList = infoList
      this.type = type
      this.checkVisible = true
      console.log(this.checkVisible)
    },
    checkInfo(values){
      let params = values
      console.log(params)
      this.$api.cultivate.infoCheck(params).then((res) => {
          this.checkVisible = false
          this.$message.success('审核成功')
          this.$refs.table.refresh(false)
          this.$refs.checkPic.form.resetFields()
      })
    }
  }
}
</script>

<style>

</style>
